﻿/*
 * Jonathan
 * Created by: Jonathan Montiverdi
 * Date: 6/13/2012
 * License: http://jonathan.codeplex.com/license
 */
using System;

namespace Jonathan.Data
{
   /// <summary>
   /// Extension methods for Jonathan.
   /// </summary>
   public static class Extensions
   {
      /// <summary>
      /// Converts the given string to a bool.
      /// </summary>
      /// <param name="value">String to convert to bool.</param>
      /// <returns>Boolean representation of string.</returns>
      public static bool ToBool (this string value)
      {
         if (string.IsNullOrEmpty (value)) return false;
         if (value.Trim ().ToLower () == "true") return true;
         if (value.Trim ().ToLower () == "false") return false;
         try
         {
            return Convert.ToBoolean (value);
         }
         catch (Exception)
         {
            return false;
         }
      }
   }
}
